{smcl}
{txt}{sf}{ul off}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\js0072\OneDrive - University of Surrey\Desktop\Full replica\results\Data_preparation.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}16 Jun 2022, 06:40:21
{txt}r; t=0.01 6:40:21

{com}. cd "$dtapath"
{res}C:\Users\js0072\OneDrive - University of Surrey\Desktop\Full replica\dta-files
{txt}r; t=0.00 6:40:21

{com}. 
. global mirror="no"  // use mirror flows to impute missing imports?
{txt}r; t=0.00 6:40:21

{com}. 
. * prepare FTA data from Baier & Bergstrand (2007, JIE) for later merge
. use "$rawdata\data_fta_fixed", clear    
{txt}r; t=0.01 6:40:21

{com}. replace iso_o = "ZAR" if iso_o=="COD"  // Changing iso codes to fit the Comtrade data (Democratic Rep of Congo and Romania were different) 
{txt}(855 real changes made)
r; t=0.01 6:40:21

{com}. replace iso_o = "ROM" if iso_o=="ROU"
{txt}(855 real changes made)
r; t=0.01 6:40:21

{com}. replace iso_d = "ZAR" if iso_d=="COD"
{txt}(855 real changes made)
r; t=0.01 6:40:21

{com}. replace iso_d = "ROM" if iso_d=="ROU"
{txt}(855 real changes made)
r; t=0.01 6:40:21

{com}. recode year (1960=1962)
{txt}(year: 9120 changes made)
r; t=0.04 6:40:21

{com}. ren iso_o exporteriso3
{res}{txt}r; t=0.02 6:40:21

{com}. ren iso_d importeriso3
{res}{txt}r; t=0.00 6:40:21

{com}. drop importer exporter
{txt}r; t=0.00 6:40:21

{com}. save tempFTABB.dta, replace
{txt}(note: file tempFTABB.dta not found)
file tempFTABB.dta saved
r; t=0.00 6:40:21

{com}. 
. * file with country names (needed to merge in cepii data later on)
. import excel "$rawdata\BB-countrylist.xlsx", sheet("Sheet1") firstrow clear
{res}{text}(4 vars, 96 obs)
r; t=0.01 6:40:21

{com}. gen reporter=strtrim(NameComtrade)
{txt}r; t=0.00 6:40:21

{com}. drop NameComtrade
{txt}r; t=0.00 6:40:21

{com}. bys reporter: keep if _n==1
{txt}(0 observations deleted)
r; t=0.00 6:40:21

{com}. save BB-countrylist_rep.dta, replace
{txt}(note: file BB-countrylist_rep.dta not found)
file BB-countrylist_rep.dta saved
r; t=0.00 6:40:21

{com}. ren reporter partner
{res}{txt}r; t=0.00 6:40:21

{com}. save BB-countrylist_par.dta, replace
{txt}(note: file BB-countrylist_par.dta not found)
file BB-countrylist_par.dta saved
r; t=0.00 6:40:21

{com}. 
. * trade data (UN Comtrade, SITC Rev 1)
. foreach x in 62-65 70-74 75-78 79-82 83-86 87-90 94-96 99-00 01-02 03-04 05 06 07 08 09-10 {c -(}
{txt}  2{com}.         import delimited "$rawdata\ComtradeBatch_1962-2010\ComtradeBatch_`x'.csv", clear encoding(ISO-8859-1)
{txt}  3{com}.                 
.         keep if length(commoditycode)==7  // work at the sub-group (4-digit) level of SITC b/c not all sub-groups are further subdivided into basic headings (5 digit)
{txt}  4{com}.         keep period reporter partner commodity* tradevalue tradeflow
{txt}  5{com}.         *keep if tradeflow=="Export"   // this seems to exclude re-exports (see WITS user manual, p.38; gross exports = exports + re-exports)
.         drop if tradeflow=="Re-Export" | tradeflow=="Re-Import"
{txt}  6{com}.         foreach name in reporter partner {c -(}
{txt}  7{com}.                 replace `name'="USA" if `name'=="USA (before 1981)"
{txt}  8{com}.                 replace `name'="Germany" if `name'=="Fmr Fed. Rep. of Germany"
{txt}  9{com}.                 replace `name'="India" if `name'=="India, excl. Sikkim"
{txt} 10{com}.                 replace `name'="Ethiopia" if `name'=="Fmr Ethiopia"
{txt} 11{com}.                 replace `name'="Belgium-Luxembourg" if `name'=="Belgium"
{txt} 12{com}.                 replace `name'="Belgium-Luxembourg" if `name'=="Luxembourg"
{txt} 13{com}.         {c )-}
{txt} 14{com}.         if "`x'"=="99-00" | "`x'"=="01-02" | "`x'"=="03-04" | "`x'"=="05" | "`x'"=="06" | "`x'"=="07" | "`x'"=="08" | "`x'"=="09-10" {c -(}
{txt} 15{com}.                 collapse (sum) tradevalue, by( period reporter partner commoditycode commoditydescription tradeflow)  // merge Belgium and Luxembourg for last years in data
{txt} 16{com}.                 drop if reporter==partner
{txt} 17{com}.         {c )-}
{txt} 18{com}.         
.         merge n:1 reporter using BB-countrylist_rep.dta  
{txt} 19{com}.         keep if _merge==3   // we only want to keep the 96 countries present in the B&B(2007) sample
{txt} 20{com}.         replace reporter=NameCepii
{txt} 21{com}.         drop _merge NameCepii
{txt} 22{com}.         merge n:1 partner using BB-countrylist_par.dta
{txt} 23{com}.         keep if _merge==3
{txt} 24{com}.         replace partner=NameCepii
{txt} 25{com}.         drop _merge NameCepii
{txt} 26{com}.         drop Original Alphabetic
{txt} 27{com}.         tab tradeflow  // make sure only exports and imports left
{txt} 28{com}.         * use mirror flows to impute missing imports 
.         gen mirrorflow=0
{txt} 29{com}.         label var mirrorflow "1: imports imputed from mirror export flow"
{txt} 30{com}.         if "$mirror"=="yes" {c -(}
{txt} 31{com}.                 preserve
{txt} 32{com}.                 keep if tradeflow=="Export"
{txt} 33{com}.                 keep reporter partner period commoditycode commoditydescription tradevalue
{txt} 34{com}.                 ren tradevalue exportvalue
{txt} 35{com}.                 ren reporter temp
{txt} 36{com}.                 ren partner reporter
{txt} 37{com}.                 ren temp partner
{txt} 38{com}.                 save tempexp.dta, replace
{txt} 39{com}.                 restore
{txt} 40{com}.                 keep if tradeflow=="Import"
{txt} 41{com}.                 merge 1:1 reporter partner period commoditycode using tempexp.dta
{txt} 42{com}.                 corr tradevalue exportvalue   // check correlation high if both mirror flows present
{txt} 43{com}.                 drop _merge
{txt} 44{com}.                 replace mirrorflow=1 if tradevalue==. & exportvalue~=.
{txt} 45{com}.                 replace tradevalue=exportvalue if tradevalue==. & exportvalue~=.
{txt} 46{com}.                 drop exportvalue
{txt} 47{com}.                 erase tempexp.dta
{txt} 48{com}.         {c )-}
{txt} 49{com}.         ren tradevalue imports
{txt} 50{com}.         drop tradeflow 
{txt} 51{com}.         save temp`x'.dta, replace
{txt} 52{com}.         
. {c )-}
{res}{text}(10 vars, 8,813,871 obs)
(5,568,931 observations deleted)
(90,935 observations deleted)
(190,540 real changes made)
(180,810 real changes made)
(42,994 real changes made)
(666 real changes made)
(0 real changes made)
(0 real changes made)
(121,997 real changes made)
(118,839 real changes made)
(31,374 real changes made)
(11,139 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         287,708
{txt}{col 9}from master{col 30}{res}         287,683{txt}  (_merge==1)
{col 9}from using{col 30}{res}              25{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,866,322{txt}  (_merge==3)
{col 5}{hline 41}
(287,708 observations deleted)
variable {bf}reporter{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(418,439 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         866,336
{txt}{col 9}from master{col 30}{res}         866,333{txt}  (_merge==1)
{col 9}from using{col 30}{res}               3{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,999,989{txt}  (_merge==3)
{col 5}{hline 41}
(866,336 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(263,620 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,058,277       52.91       52.91
{txt}     Import {c |}{res}    941,712       47.09      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,999,989      100.00
{txt}(note: file temp62-65.dta not found)
file temp62-65.dta saved
{res}{text}(10 vars, 17,664,939 obs)
(11,393,366 observations deleted)
(170,995 observations deleted)
(274,844 real changes made)
(284,538 real changes made)
(80,075 real changes made)
(19,965 real changes made)
(0 real changes made)
(0 real changes made)
(228,482 real changes made)
(219,666 real changes made)
(58,486 real changes made)
(18,258 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         801,141
{txt}{col 9}from master{col 30}{res}         801,130{txt}  (_merge==1)
{col 9}from using{col 30}{res}              11{txt}  (_merge==2)

{col 5}matched{col 30}{res}       5,299,448{txt}  (_merge==3)
{col 5}{hline 41}
(801,141 observations deleted)
variable {bf}reporter{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(701,178 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,566,935
{txt}{col 9}from master{col 30}{res}       1,566,934{txt}  (_merge==1)
{col 9}from using{col 30}{res}               1{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,732,514{txt}  (_merge==3)
{col 5}{hline 41}
(1,566,935 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(485,001 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,852,065       49.62       49.62
{txt}     Import {c |}{res}  1,880,449       50.38      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,732,514      100.00
{txt}(note: file temp70-74.dta not found)
file temp70-74.dta saved
{res}{text}(10 vars, 16,242,209 obs)
(10,476,807 observations deleted)
(176,239 observations deleted)
(237,605 real changes made)
(247,117 real changes made)
(0 real changes made)
(5,048 real changes made)
(0 real changes made)
(0 real changes made)
(207,118 real changes made)
(191,464 real changes made)
(0 real changes made)
(12,832 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         736,942
{txt}{col 9}from master{col 30}{res}         736,934{txt}  (_merge==1)
{col 9}from using{col 30}{res}               8{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,852,229{txt}  (_merge==3)
{col 5}{hline 41}
(736,942 observations deleted)
variable {bf}reporter{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(669,651 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,409,347
{txt}{col 9}from master{col 30}{res}       1,409,347{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,442,882{txt}  (_merge==3)
{col 5}{hline 41}
(1,409,347 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(455,229 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,673,253       48.60       48.60
{txt}     Import {c |}{res}  1,769,629       51.40      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,442,882      100.00
{txt}(note: file temp75-78.dta not found)
file temp75-78.dta saved
{res}{text}(10 vars, 17,014,052 obs)
(10,966,977 observations deleted)
(208,229 observations deleted)
(124,343 real changes made)
(257,644 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(104,825 real changes made)
(189,059 real changes made)
(0 real changes made)
(12,686 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         809,430
{txt}{col 9}from master{col 30}{res}         809,415{txt}  (_merge==1)
{col 9}from using{col 30}{res}              15{txt}  (_merge==2)

{col 5}matched{col 30}{res}       5,029,431{txt}  (_merge==3)
{col 5}{hline 41}
(809,430 observations deleted)
(691,541 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,425,110
{txt}{col 9}from master{col 30}{res}       1,425,110{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,604,321{txt}  (_merge==3)
{col 5}{hline 41}
(1,425,110 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(469,762 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,785,213       49.53       49.53
{txt}     Import {c |}{res}  1,819,108       50.47      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,604,321      100.00
{txt}(note: file temp79-82.dta not found)
file temp79-82.dta saved
{res}{text}(10 vars, 16,970,450 obs)
(10,974,362 observations deleted)
(203,602 observations deleted)
(0 real changes made)
(263,285 real changes made)
(0 real changes made)
(18,638 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(185,837 real changes made)
(0 real changes made)
(13,440 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         723,770
{txt}{col 9}from master{col 30}{res}         723,755{txt}  (_merge==1)
{col 9}from using{col 30}{res}              15{txt}  (_merge==2)

{col 5}matched{col 30}{res}       5,068,731{txt}  (_merge==3)
{col 5}{hline 41}
(723,770 observations deleted)
variable {bf}reporter{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(713,780 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,438,305
{txt}{col 9}from master{col 30}{res}       1,438,305{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,630,426{txt}  (_merge==3)
{col 5}{hline 41}
(1,438,305 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(473,235 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,809,818       49.85       49.85
{txt}     Import {c |}{res}  1,820,608       50.15      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,630,426      100.00
{txt}(note: file temp83-86.dta not found)
file temp83-86.dta saved
{res}{text}(10 vars, 18,782,779 obs)
(12,182,194 observations deleted)
(234,430 observations deleted)
(0 real changes made)
(283,987 real changes made)
(0 real changes made)
(19,496 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(188,489 real changes made)
(0 real changes made)
(14,047 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         764,974
{txt}{col 9}from master{col 30}{res}         764,955{txt}  (_merge==1)
{col 9}from using{col 30}{res}              19{txt}  (_merge==2)

{col 5}matched{col 30}{res}       5,601,200{txt}  (_merge==3)
{col 5}{hline 41}
(764,974 observations deleted)
(722,995 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,547,832
{txt}{col 9}from master{col 30}{res}       1,547,832{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,053,368{txt}  (_merge==3)
{col 5}{hline 41}
(1,547,832 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(524,357 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  2,065,791       50.96       50.96
{txt}     Import {c |}{res}  1,987,577       49.04      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  4,053,368      100.00
{txt}(note: file temp87-90.dta not found)
file temp87-90.dta saved
{res}{text}(10 vars, 19,609,007 obs)
(12,698,799 observations deleted)
(235,861 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,170,706
{txt}{col 9}from master{col 30}{res}       1,170,701{txt}  (_merge==1)
{col 9}from using{col 30}{res}               5{txt}  (_merge==2)

{col 5}matched{col 30}{res}       5,503,646{txt}  (_merge==3)
{col 5}{hline 41}
(1,170,706 observations deleted)
(662,797 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,630,890
{txt}{col 9}from master{col 30}{res}       1,630,890{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,872,756{txt}  (_merge==3)
{col 5}{hline 41}
(1,630,890 observations deleted)
variable {bf}partner{sf} was {bf}{res}str32{sf}{txt} now {bf}{res}str34{sf}
{txt}(488,508 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,902,576       49.13       49.13
{txt}     Import {c |}{res}  1,970,180       50.87      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,872,756      100.00
{txt}(note: file temp94-96.dta not found)
file temp94-96.dta saved
{res}{text}(10 vars, 16,554,487 obs)
(10,736,290 observations deleted)
(193,274 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(112,708 real changes made)
(29,233 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(103,904 real changes made)
(22,430 real changes made)
(5,269 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,361,994
{txt}{col 9}from master{col 30}{res}       1,361,988{txt}  (_merge==1)
{col 9}from using{col 30}{res}               6{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,211,016{txt}  (_merge==3)
{col 5}{hline 41}
(1,361,994 observations deleted)
(466,087 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,264,232
{txt}{col 9}from master{col 30}{res}       1,264,232{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,946,784{txt}  (_merge==3)
{col 5}{hline 41}
(1,264,232 observations deleted)
(361,611 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,409,863       47.84       47.84
{txt}     Import {c |}{res}  1,536,921       52.16      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  2,946,784      100.00
{txt}(note: file temp99-00.dta not found)
file temp99-00.dta saved
{res}{text}(10 vars, 18,102,073 obs)
(11,760,882 observations deleted)
(203,841 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(115,086 real changes made)
(33,725 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(111,993 real changes made)
(25,820 real changes made)
(9,363 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,541,745
{txt}{col 9}from master{col 30}{res}       1,541,740{txt}  (_merge==1)
{col 9}from using{col 30}{res}               5{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,532,524{txt}  (_merge==3)
{col 5}{hline 41}
(1,541,745 observations deleted)
(507,536 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,363,861
{txt}{col 9}from master{col 30}{res}       1,363,861{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,168,663{txt}  (_merge==3)
{col 5}{hline 41}
(1,363,861 observations deleted)
(384,513 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,496,858       47.24       47.24
{txt}     Import {c |}{res}  1,671,805       52.76      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,168,663      100.00
{txt}(note: file temp01-02.dta not found)
file temp01-02.dta saved
{res}{text}(10 vars, 19,250,137 obs)
(12,512,083 observations deleted)
(211,202 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(117,302 real changes made)
(34,570 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(114,988 real changes made)
(28,082 real changes made)
(10,727 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,660,163
{txt}{col 9}from master{col 30}{res}       1,660,158{txt}  (_merge==1)
{col 9}from using{col 30}{res}               5{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,799,077{txt}  (_merge==3)
{col 5}{hline 41}
(1,660,163 observations deleted)
(534,937 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,460,926
{txt}{col 9}from master{col 30}{res}       1,460,926{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,338,151{txt}  (_merge==3)
{col 5}{hline 41}
(1,460,926 observations deleted)
(396,961 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,585,411       47.49       47.49
{txt}     Import {c |}{res}  1,752,740       52.51      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,338,151      100.00
{txt}(note: file temp03-04.dta not found)
file temp03-04.dta saved
{res}{text}(10 vars, 10,441,180 obs)
(6,785,036 observations deleted)
(158,299 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(61,657 real changes made)
(16,805 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(60,532 real changes made)
(15,100 real changes made)
(6,450 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         915,076
{txt}{col 9}from master{col 30}{res}         915,070{txt}  (_merge==1)
{col 9}from using{col 30}{res}               6{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,547,194{txt}  (_merge==3)
{col 5}{hline 41}
(915,076 observations deleted)
(277,588 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         773,521
{txt}{col 9}from master{col 30}{res}         773,521{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,773,673{txt}  (_merge==3)
{col 5}{hline 41}
(773,521 observations deleted)
(209,791 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}    837,983       47.25       47.25
{txt}     Import {c |}{res}    935,690       52.75      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,773,673      100.00
{txt}(note: file temp05.dta not found)
file temp05.dta saved
{res}{text}(10 vars, 10,627,007 obs)
(6,907,149 observations deleted)
(143,064 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(61,365 real changes made)
(17,235 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(61,329 real changes made)
(15,468 real changes made)
(6,434 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         937,583
{txt}{col 9}from master{col 30}{res}         937,576{txt}  (_merge==1)
{col 9}from using{col 30}{res}               7{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,602,930{txt}  (_merge==3)
{col 5}{hline 41}
(937,583 observations deleted)
(287,528 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         795,956
{txt}{col 9}from master{col 30}{res}         795,956{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,806,974{txt}  (_merge==3)
{col 5}{hline 41}
(795,956 observations deleted)
(212,918 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}    858,535       47.51       47.51
{txt}     Import {c |}{res}    948,439       52.49      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,806,974      100.00
{txt}(note: file temp06.dta not found)
file temp06.dta saved
{res}{text}(10 vars, 10,837,315 obs)
(7,036,555 observations deleted)
(165,814 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(65,256 real changes made)
(17,399 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(61,962 real changes made)
(16,056 real changes made)
(5,983 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         985,353
{txt}{col 9}from master{col 30}{res}         985,345{txt}  (_merge==1)
{col 9}from using{col 30}{res}               8{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,612,884{txt}  (_merge==3)
{col 5}{hline 41}
(985,353 observations deleted)
(286,565 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         804,783
{txt}{col 9}from master{col 30}{res}         804,783{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,808,101{txt}  (_merge==3)
{col 5}{hline 41}
(804,783 observations deleted)
(213,046 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}    862,006       47.67       47.67
{txt}     Import {c |}{res}    946,095       52.33      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,808,101      100.00
{txt}(note: file temp07.dta not found)
file temp07.dta saved
{res}{text}(10 vars, 10,762,603 obs)
(6,987,311 observations deleted)
(158,737 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(70,447 real changes made)
(17,656 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(60,920 real changes made)
(16,213 real changes made)
(5,808 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         949,041
{txt}{col 9}from master{col 30}{res}         949,032{txt}  (_merge==1)
{col 9}from using{col 30}{res}               9{txt}  (_merge==2)

{col 5}matched{col 30}{res}       2,630,450{txt}  (_merge==3)
{col 5}{hline 41}
(949,041 observations deleted)
(297,153 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         817,399
{txt}{col 9}from master{col 30}{res}         817,399{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       1,813,051{txt}  (_merge==3)
{col 5}{hline 41}
(817,399 observations deleted)
(212,066 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}    867,446       47.84       47.84
{txt}     Import {c |}{res}    945,605       52.16      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  1,813,051      100.00
{txt}(note: file temp08.dta not found)
file temp08.dta saved
{res}{text}(10 vars, 18,484,953 obs)
(12,004,177 observations deleted)
(265,547 observations deleted)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(142,750 real changes made)
(40,600 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(0 real changes made)
(103,246 real changes made)
(28,559 real changes made)
(9,896 observations deleted)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,488,504
{txt}{col 9}from master{col 30}{res}       1,488,492{txt}  (_merge==1)
{col 9}from using{col 30}{res}              12{txt}  (_merge==2)

{col 5}matched{col 30}{res}       4,654,248{txt}  (_merge==3)
{col 5}{hline 41}
(1,488,504 observations deleted)
(519,320 real changes made)
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}       1,448,151
{txt}{col 9}from master{col 30}{res}       1,448,151{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}       3,206,097{txt}  (_merge==3)
{col 5}{hline 41}
(1,448,151 observations deleted)
(375,972 real changes made)

 Trade Flow {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
     Export {c |}{res}  1,550,392       48.36       48.36
{txt}     Import {c |}{res}  1,655,705       51.64      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res}  3,206,097      100.00
{txt}(note: file temp09-10.dta not found)
file temp09-10.dta saved
r; t=1019.44 6:57:21

{com}.         
. use temp62-65.dta, replace
{txt}r; t=0.12 6:57:21

{com}. foreach x in 70-74 75-78 79-82 83-86 87-90 94-96 99-00 01-02 03-04 05 06 07 08 09-10 {c -(}  
{txt}  2{com}.         append using temp`x'.dta
{txt}  3{com}. {c )-}
{txt}{p 0 7 2}
(note: variable
partner was 
str34, now str44 to accommodate using data's values)
{p_end}
r; t=12.21 6:57:33

{com}. ren period year
{res}{txt}r; t=0.00 6:57:33

{com}. keep if year==1962 | year==1965 | year==1970 | year==1975 | year==1980 | year==1985 | year==1990 | year==1995 | year==2000 | year==2005 | year==2010
{txt}(32,779,785 observations deleted)
r; t=7.10 6:57:40

{com}. codebook reporter partner // check we get all 96 countries in B&B 

{txt}{hline}
{res}reporter{right:Reporter}
{txt}{hline}

{col 19}type:  string ({res}str34{txt})

{col 10}unique values:  {res}96{col 51}{txt}missing "":  {res}0{txt}/{res}11,417,965

{txt}{col 15}examples:  {res}"Cyprus"
{col 26}"Hong Kong"
{col 26}"Morocco"
{col 26}"Sweden"

{txt}{col 16}warning:  variable has embedded blanks

{txt}{hline}
{res}partner{right:Partner}
{txt}{hline}

{col 19}type:  string ({res}str44{txt}), but longest is str34

{col 10}unique values:  {res}96{col 51}{txt}missing "":  {res}0{txt}/{res}11,417,965

{txt}{col 15}examples:  {res}"Cote d'Ivoire"
{col 26}"Hong Kong"
{col 26}"Morocco"
{col 26}"Spain"

{txt}{col 16}warning:  variable has embedded blanks
r; t=42.52 6:58:23

{com}. sort reporter partner commoditycode year
{txt}r; t=18.13 6:58:41

{com}. compress
  {txt}variable {bf}mirrorflow{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}partner{sf} was {bf}{res}str44{sf}{txt} now {bf}{res}str34{sf}
  {txt}variable {bf}commoditycode{sf} was {bf}{res}str8{sf}{txt} now {bf}{res}str7{sf}
{txt}  (159,851,510 bytes saved)
r; t=3.47 6:58:44

{com}. save BB_allyears.dta, replace
{txt}(note: file BB_allyears.dta not found)
file BB_allyears.dta saved
r; t=0.69 6:58:45

{com}. foreach x in 62-65 70-74 75-78 79-82 83-86 87-90 94-96 99-00 01-02 03-04 05 06 07 08 09-10 {c -(}
{txt}  2{com}.         erase temp`x'.dta
{txt}  3{com}. {c )-}
{txt}r; t=0.48 6:58:45

{com}. for any BB-countrylist_par BB-countrylist_rep: erase X.dta

{res}->  erase BB-countrylist_par.dta

->  erase BB-countrylist_rep.dta
{txt}r; t=0.00 6:58:45

{com}. 
. * numerous duplicates present in BB_allyears.dta; Already seem to be there in the
. * original data. For now, simply take averages to avoid problems with fillin below
. collapse (mean) imports, by(reporter partner commoditycode commoditydescription year) 
{txt}r; t=15.06 6:59:00

{com}. save BB_allyears_noduplicates.dta, replace
{txt}(note: file BB_allyears_noduplicates.dta not found)
file BB_allyears_noduplicates.dta saved
r; t=0.53 6:59:01

{com}. 
. 
. * merge in cepii identifiers and rectangularise data
. use "$rawdata\geo_cepii.dta", replace
{txt}r; t=0.00 6:59:01

{com}. replace country="Cote d'Ivoire" if iso3=="CIV"
{txt}(2 real changes made)
r; t=0.00 6:59:01

{com}. bys iso3: keep if _n==1
{txt}(13 observations deleted)
r; t=0.00 6:59:01

{com}. ren country reporter
{res}{txt}r; t=0.00 6:59:01

{com}. save tempgeo_rep.dta, replace
{txt}(note: file tempgeo_rep.dta not found)
file tempgeo_rep.dta saved
r; t=0.00 6:59:01

{com}. ren reporter partner
{res}{txt}r; t=0.00 6:59:01

{com}. save tempgeo_par.dta, replace
{txt}(note: file tempgeo_par.dta not found)
file tempgeo_par.dta saved
r; t=0.00 6:59:01

{com}. 
. use BB_allyears_noduplicates.dta, replace
{txt}r; t=0.44 6:59:01

{com}. merge n:1 reporter using tempgeo_rep.dta, keepusing(iso3)
{res}{txt}{p 0 7 2}
(note: variable
reporter was 
str34, now str39 to accommodate using data's values)
{p_end}

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             129
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}             129{txt}  (_merge==2)

{col 5}matched{col 30}{res}       8,739,998{txt}  (_merge==3)
{col 5}{hline 41}
r; t=2.59 6:59:04

{com}. ren iso3 importeriso3
{res}{txt}r; t=0.00 6:59:04

{com}. drop if _merge==2
{txt}(129 observations deleted)
r; t=0.90 6:59:05

{com}. drop _merge
{txt}r; t=0.00 6:59:05

{com}. merge n:1 partner using tempgeo_par.dta, keepusing(iso3)
{res}{txt}{p 0 7 2}
(note: variable
partner was 
str34, now str39 to accommodate using data's values)
{p_end}

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}             129
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}             129{txt}  (_merge==2)

{col 5}matched{col 30}{res}       8,739,998{txt}  (_merge==3)
{col 5}{hline 41}
r; t=10.62 6:59:16

{com}. ren iso3 exporteriso3
{res}{txt}r; t=0.00 6:59:16

{com}. drop if _merge==2
{txt}(129 observations deleted)
r; t=0.88 6:59:16

{com}. drop _merge
{txt}r; t=0.00 6:59:16

{com}. 
. encode commoditydescription, gen(commodityname)
{txt}r; t=12.58 6:59:29

{com}. keep exporteriso3 importeriso3 year commoditycode commodityname imports 
{txt}r; t=0.14 6:59:29

{com}. 
. 
. * Option 1: rectangularisation using fillin
. fillin exporteriso3 importeriso3 year commoditycode
{txt}r; t=384.95 7:05:54

{com}. replace imports=0 if _fillin==1
{txt}(54,620,002 real changes made)
r; t=0.82 7:05:55

{com}. drop if exporteriso3==importeriso3
{txt}(660,000 observations deleted)
r; t=2.97 7:05:58

{com}. save BB_allyears_zeros.dta, replace
{txt}(note: file BB_allyears_zeros.dta not found)
file BB_allyears_zeros.dta saved
r; t=1.23 7:05:59

{com}. * check that fillin generates an equal number of products per country pair
. egen pair=concat(exporteriso3 importeriso3)
{txt}r; t=24.18 7:06:23

{com}. egen sic_count=count(commoditycode), by(pair)
{txt}r; t=9.25 7:06:33

{com}. tab sic_count  // should be 625 products*11 years = 6875

  {txt}sic_count {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
       6875 {c |}{res} 62,700,000      100.00      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res} 62,700,000      100.00
{txt}r; t=1.31 7:06:34

{com}. 
. replace imports=0 if _fillin==1
{txt}(0 real changes made)
r; t=0.70 7:06:35

{com}. drop if exporteriso3==importeriso3
{txt}(0 observations deleted)
r; t=2.23 7:06:37

{com}. save BB_allyears_zeros.dta, replace 
{txt}file BB_allyears_zeros.dta saved
r; t=8.77 7:06:46

{com}. for any geo_par geo_rep: erase tempX.dta

{res}->  erase tempgeo_par.dta

->  erase tempgeo_rep.dta
{txt}r; t=0.00 7:06:46

{com}. 
. 
. /* Option 2: use cross command for rectangularisation if fillin doesn't work properly
> preserve
> bys exporteriso3: keep if _n==1
> keep exporteriso3
> save BB_exp_iso3.dta, replace
> restore
> preserve
> bys importeriso3: keep if _n==1
> keep importeriso3
> save BB_imp_iso3.dta, replace
> restore
> preserve
> bys year: keep if _n==1
> keep year
> save BB_years.dta, replace
> restore
> preserve
> bys commoditycode: keep if _n==1
> keep commoditycode
> save BB_productcodes.dta, replace
> 
> use BB_exp_iso3.dta, replace
> cross using BB_imp_iso3
> count // dataset has all possible country combinations from B&B (2007), yielding
> * 96*96 = 9,216 obs.
> cross using BB_productcodes.dta
> count // dataset now has all 625 product codes for each country pair, yielding
> *96*96*625 = 5,760,000 obs.
> cross using BB_years  // finally add all 11 years for each country-pair-product 
> *combinations, yielding 96*96*625*11=63,360,000 obs
> save BB_rect.dta, replace
> merge 1:1 exporteriso3 importeriso3 commoditycode year using tempdata.dta
> */
. 
. 
. * merge in gravity variables (CEPII)
. use "$rawdata\dist_cepii.dta", replace
{txt}r; t=0.01 7:06:46

{com}. ren iso_o exporteriso3
{res}{txt}r; t=0.00 7:06:46

{com}. ren iso_d importeriso3
{res}{txt}r; t=0.00 7:06:46

{com}. save tempdist.dta, replace
{txt}(note: file tempdist.dta not found)
file tempdist.dta saved
r; t=0.00 7:06:46

{com}. use BB_allyears_zeros.dta, replace  
{txt}r; t=1.80 7:06:47

{com}. merge n:1 importeriso3 exporteriso3 using tempdist.dta
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}          41,056
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}          41,056{txt}  (_merge==2)

{col 5}matched{col 30}{res}      62,700,000{txt}  (_merge==3)
{col 5}{hline 41}
r; t=71.63 7:07:59

{com}. keep if _merge==3
{txt}(41,056 observations deleted)
r; t=2.02 7:08:01

{com}. drop _merge
{txt}r; t=0.01 7:08:01

{com}. keep exporteriso3 importeriso3 year commoditycode commodityname imports comlang_off comcol curcol col45 distw _fillin
{txt}r; t=0.91 7:08:02

{com}. erase tempdist.dta
{txt}r; t=0.00 7:08:02

{com}. 
. 
. * FTA variable from Limao (2016)
. for any importeriso3 exporteriso3: replace X="SUD" if X=="SDN"   // code for Sudan

{res}->  replace importeriso3="SUD" if importeriso3=="SDN"
{txt}(653,125 real changes made)

{res}->  replace exporteriso3="SUD" if exporteriso3=="SDN"
{txt}(653,125 real changes made)
r; t=4.31 7:08:06

{com}. merge n:1 importeriso3 exporteriso3 year using "$rawdata\limao_handbook_pta.dta", keepusing(EIA gatt_year_i wto_year_i gatt_year_j wto_year_j)
{res}{txt}{p 0 7 2}
(note: variable
year was 
int, now float to accommodate using data's values)
{p_end}

{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}         434,500
{txt}{col 9}from master{col 30}{res}               0{txt}  (_merge==1)
{col 9}from using{col 30}{res}         434,500{txt}  (_merge==2)

{col 5}matched{col 30}{res}      62,700,000{txt}  (_merge==3)
{col 5}{hline 41}
r; t=77.97 7:09:24

{com}. drop if _merge==2
{txt}(434,500 observations deleted)
r; t=1.96 7:09:26

{com}. drop _merge
{txt}r; t=0.00 7:09:26

{com}. gen WTO_j = (wto_year_j <= year | gatt_year_j <= year) // the following 13 lines are from Limao's do file
{txt}r; t=0.93 7:09:27

{com}. gen WTO_i = (wto_year_i <= year | gatt_year_i <= year) 
{txt}r; t=1.99 7:09:29

{com}. gen WTO          = (WTO_j == 1 & WTO_i == 1) 
{txt}r; t=0.87 7:09:30

{com}. drop wto_year_j wto_year_i gatt*
{txt}r; t=0.66 7:09:31

{com}. tab EIA if EIA != -999, gen(EIA_) // generate 7 dummies for EIA 0 to 6 (see Limao, p.286)

  {txt}index for {c |}
integration {c |}
 agreements {c |}
 - Baier et {c |}
         al {c |}      Freq.     Percent        Cum.
{hline 12}{c +}{hline 35}
          0 {c |}{res} 47,659,375       79.63       79.63
{txt}          1 {c |}{res}  6,771,875       11.31       90.94
{txt}          2 {c |}{res}  2,407,500        4.02       94.97
{txt}          3 {c |}{res}  1,861,250        3.11       98.08
{txt}          4 {c |}{res}    390,000        0.65       98.73
{txt}          5 {c |}{res}    473,750        0.79       99.52
{txt}          6 {c |}{res}    287,500        0.48      100.00
{txt}{hline 12}{c +}{hline 35}
      Total {c |}{res} 59,851,250      100.00
{txt}r; t=7.82 7:09:39

{com}. rename EIA_1 No_Agreem
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_2 NRPTA
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_3 RPTA   
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_4 FTA
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_5 CU
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_6 CM
{res}{txt}r; t=0.00 7:09:39

{com}. rename EIA_7 EU
{res}{txt}r; t=0.00 7:09:39

{com}. gen PTA = RPTA+FTA+CU+CM+EU 
{txt}(2,848,750 missing values generated)
r; t=2.22 7:09:41

{com}. 
. * FTA variable from Baier & Bergstrand (2007, JIE)
. for any importeriso3 exporteriso3: replace X="SDN" if X=="SUD"  

{res}->  replace importeriso3="SDN" if importeriso3=="SUD"
{txt}(653,125 real changes made)

{res}->  replace exporteriso3="SDN" if exporteriso3=="SUD"
{txt}(653,125 real changes made)
r; t=4.16 7:09:45

{com}. merge n:1 importeriso3 exporteriso3 year using tempFTABB.dta // _merge==1 are years 2005 and 2010 which are not in B&B
{res}
{txt}{col 5}Result{col 38}# of obs.
{col 5}{hline 41}
{col 5}not matched{col 30}{res}      11,400,000
{txt}{col 9}from master{col 30}{res}      11,400,000{txt}  (_merge==1)
{col 9}from using{col 30}{res}               0{txt}  (_merge==2)

{col 5}matched{col 30}{res}      51,300,000{txt}  (_merge==3)
{col 5}{hline 41}
r; t=67.73 7:10:53

{com}. drop _merge
{txt}r; t=0.00 7:10:53

{com}. label var fta "Trade agreements coded from Baier and Bergstrand (2007, JIE), Table 3"
{txt}r; t=0.00 7:10:53

{com}. label var scott_fta "Trade agreements from Baier and Bergstrand (2007, JIE) as sent by Scott Baier"
{txt}r; t=0.00 7:10:53

{com}. erase tempFTABB.dta
{txt}r; t=0.00 7:10:53

{com}. compress
  {txt}variable {bf}year{sf} was {bf}{res}float{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}commodityname{sf} was {bf}{res}long{sf}{txt} now {bf}{res}int{sf}
  {txt}variable {bf}WTO_j{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}WTO_i{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}WTO{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}PTA{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
  {txt}variable {bf}fta{sf} was {bf}{res}float{sf}{txt} now {bf}{res}byte{sf}
{txt}  (1,191,300,000 bytes saved)
r; t=20.72 7:11:13

{com}. 
. 
. 
. * save data
. if "$mirror"=="yes" {c -(}
.         save BB_allyears_all_zeros.dta, replace
{txt}r; t=0.00 7:11:13
{com}. {c )-}
{txt}r; t=0.00 7:11:13

{com}. else {c -(}
.         save BB_allyears_all_zeros_nomirror.dta, replace
{txt}(note: file BB_allyears_all_zeros_nomirror.dta not found)
file BB_allyears_all_zeros_nomirror.dta saved
r; t=2.21 7:11:16
{com}. {c )-}
{txt}r; t=2.21 7:11:16

{com}. drop if _fillin==1
{txt}(53,960,002 observations deleted)
r; t=2.30 7:11:18

{com}. drop _fillin
{txt}r; t=0.10 7:11:18

{com}. if "$mirror"=="yes" {c -(}
.         save BB_allyears_all_nozeros.dta, replace
{txt}r; t=0.00 7:11:18
{com}. {c )-}
{txt}r; t=0.01 7:11:18

{com}. else {c -(}
.         save BB_allyears_all_nozeros_nomirror.dta, replace
{txt}(note: file BB_allyears_all_nozeros_nomirror.dta not found)
file BB_allyears_all_nozeros_nomirror.dta saved
r; t=0.21 7:11:18
{com}. {c )-}
{txt}r; t=0.21 7:11:18

{com}. 
. erase BB_allyears.dta 
{txt}r; t=0.12 7:11:18

{com}. erase BB_allyears_noduplicates.dta 
{txt}r; t=0.10 7:11:18

{com}. erase BB_allyears_zeros.dta
{txt}r; t=0.18 7:11:19

{com}. 
. log close
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\js0072\OneDrive - University of Surrey\Desktop\Full replica\results\Data_preparation.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}16 Jun 2022, 07:11:19
{txt}{.-}
{smcl}
{txt}{sf}{ul off}